package com.serverlite.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    public static final int SECOND = 1000;
    public static final int MINUTE = SECOND * 60;
    public static final int HOUR = MINUTE * 60;
    public static final long DAY = HOUR * 24;
    public static final long WEEK = DAY * 7;
    public static final long YEAR = DAY * 356;

    final static public String FULL_ST_FORMAT = "yyyy-MM-dd HH:mm:ss";
    final static public String FULL_J_FORMAT = "yyyy/MM/dd HH:mm:ss";
    final static public String CURRENCY_ST_FORMAT = "yyyy-MM-dd HH:mm";
    final static public String CURRENCY_J_FORMAT = "yyyy/MM/dd HH:mm";
    final static public String DATA_FORMAT = "yyyyMMddHHmmss";
    final static public String ST_FORMAT = "yyyy-MM-dd HH:mm";
    final static public String ST_CN_FORMAT = "yyyy年MM月dd日 HH:mm";
    final static public String CN_FORMAT = "yy年MM月dd日HH:mm";
    final static public String DAY_FORMAT = "yyyy-MM-dd";
    final static public String SHORT_DATE_FORMAT = "yy-MM-dd";
    final static public String YEAR_FORMAT = "yyyy";
    final static public String YEAR_MONTH = "yyyy-MM";
    final static public String MONTH_FORMAT = "MM";
    final static public String TODAYNO_FORMAT = "dd";

    final static public String CREATE_NO = "yyyyMMddHHmmss";

    public static String getDateTimeSequence() {
        SimpleDateFormat sdf = new SimpleDateFormat(DATA_FORMAT);
        return sdf.format(new Date());
    }

    public static String getDate(long second) {
        SimpleDateFormat sdf = new SimpleDateFormat(FULL_ST_FORMAT);
        return sdf.format(new Date(second));
    }

    public static String getToday() {
        SimpleDateFormat sdf = new SimpleDateFormat(DAY_FORMAT);
        return sdf.format(new Date());
    }

    public static String getNow() {
        SimpleDateFormat sdf = new SimpleDateFormat(FULL_ST_FORMAT);
        return sdf.format(new Date());
    }

    public static String getShortDate() {
        SimpleDateFormat sdf = new SimpleDateFormat(SHORT_DATE_FORMAT);
        return sdf.format(new Date());
    }

    public static String getYearMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat(YEAR_MONTH);
        return sdf.format(new Date());
    }

    public static String getYear() {
        SimpleDateFormat sdf = new SimpleDateFormat(YEAR_FORMAT);
        return sdf.format(new Date());
    }

    public static String getMonth() {
        SimpleDateFormat sdf = new SimpleDateFormat(MONTH_FORMAT);
        String month = sdf.format(new Date());
        if (month.startsWith("0")) {
            month = month.substring(1);
        }
        return month;
    }

    public static String getTodayNo() {
        SimpleDateFormat sdf = new SimpleDateFormat(TODAYNO_FORMAT);
        String today = sdf.format(new Date());
        if (today.startsWith("0")) {
            today = today.substring(1);
        }
        return today;
    }

    public static String getMillisecond() {
        return "" + new Date().getTime();
    }

    public static String createNoByNow() {
        SimpleDateFormat sdf = new SimpleDateFormat(CREATE_NO);
        String No = sdf.format(new Date());
        return No;
    }

    public static long getQuot(String time1, String time2)
            throws java.text.ParseException {
        long quot = 0;
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date1 = ft.parse(time1);
            Date date2 = ft.parse(time2);
            quot = date1.getTime() - date2.getTime();
            quot = quot / 1000 / 60 / 60 / 24;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return quot;
    }

}
